package com.inno.thread.innot.communication;

import java.util.concurrent.TimeUnit;

/**
 * 双人游戏，只要其中一个人over，游戏就over了。
 *
 * @author: May
 * @date 2020/7/3
 */
public class DoublePersonGame implements Runnable {

    private Game game;

    public DoublePersonGame() {
    }

    public DoublePersonGame(Game game) {
        this.game = game;
    }

    @Override
    public void run() {
        while (game.isRunning()) {
            game.shooting();
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void cancel() {
        game.setRunning(false);
    }
}
